package com.starblink.web.app

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.blankj.utilcode.util.ProcessUtils
import com.starblink.web.app.databinding.ActivityMainBinding
import com.starblink.web.app.databinding.ActivityWebDemoBinding
import com.starblink.web.broadcast.WebViewInitBoastCast
import com.starblink.web.util.GuangWebViewPool
import com.starblink.web.util.WebCacheUtil
import com.starblink.web.util.WebLog
import com.starblink.web.util.WebUtil

class MainActivity : AppCompatActivity() {
    private lateinit var viewBinding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        viewBinding = ActivityMainBinding.inflate(layoutInflater)
        super.onCreate(savedInstanceState)
        setContentView(viewBinding.root)

        initView()
    }

    private fun initView(){
        // init WebView 三种方式
//        WebUtil.initWebViewPool(this)
        // Cross process init WebView
        sendBroadcast(Intent(this, WebViewInitBoastCast::class.java))
        WebLog.d("CurrentProcess", "MainActivity 当前进程：${ProcessUtils.getCurrentProcessName()}")
        val url = "https://www.baidu.com"
        viewBinding.btnPre.setOnClickListener {
            WebCacheUtil.preLoadUrl(url)
        }
        viewBinding.btnJump.setOnClickListener {
            val intent = Intent(this,WebDemoActivity::class.java)
            intent.putExtra("mWebUrl",url)
            startActivity(intent)
        }
    }
}